home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / editor / pref-composer.js < prev    next >
Encoding:
Text File  |  2002-04-09  |  10.1 KB  |  303 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  */
  22. // This is mostly a modified version of code in EdColorProps.xul
  23.  
  24. // Initialize in case we can't get them from prefs???
  25. const defaultTextColor="#000000";
  26. const defaultLinkColor="#000099";
  27. const defaultActiveColor="#000099";
  28. const defaultVisitedColor="#990099";
  29. const defaultBackgroundColor="#FFFFFF";
  30.  
  31. var customTextColor;
  32. var customLinkColor;
  33. var customActiveColor;
  34. var customVisitedColor;
  35. var customBackgroundColor;
  36. var previewBGColor;
  37. var backgroundImage = "";
  38.  
  39. // Strings we use often
  40. const styleStr =       "style";
  41. const textStr =        "text";
  42. const linkStr =        "link";
  43. const vlinkStr =       "vlink";
  44. const alinkStr =       "alink";
  45. const bgcolorStr =     "bgcolor";
  46. const backgroundStr =  "background";
  47. const colorStyle =     "color: ";
  48. const backColorStyle = "background-color: ";
  49. const backImageStyle = "; background-image: url(";
  50.  
  51. var browserColors;
  52. var dialog;
  53.  
  54. function Startup()
  55. {
  56.   gDialog.ColorPreview = document.getElementById("ColorPreview");
  57.   gDialog.NormalText = document.getElementById("NormalText");
  58.   gDialog.LinkText = document.getElementById("LinkText");
  59.   gDialog.ActiveLinkText = document.getElementById("ActiveLinkText");
  60.   gDialog.VisitedLinkText = document.getElementById("VisitedLinkText");
  61.   gDialog.DefaultColorsRadio = document.getElementById("DefaultColorsRadio");
  62.   gDialog.CustomColorsRadio = document.getElementById("CustomColorsRadio");
  63.   gDialog.BackgroundImageInput = document.getElementById("BackgroundImageInput");
  64.  
  65.   // The data elements that hold the pref values
  66.   gDialog.NormalData = document.getElementById("textData");
  67.   gDialog.LinkData = document.getElementById("linkData");
  68.   gDialog.ActiveLinkData = document.getElementById("aLinkData");
  69.   gDialog.VisitedLinkData = document.getElementById("fLinkData");
  70.   gDialog.BackgroundColorData = document.getElementById("backgroundColorData");
  71.   gDialog.BackgroundImageData = document.getElementById("backgroundImageData");
  72.  
  73.   browserColors = GetDefaultBrowserColors();
  74.  
  75.   // Use author's browser pref colors passed into dialog
  76.   defaultTextColor = browserColors.TextColor;
  77.   defaultLinkColor = browserColors.LinkColor;
  78.   // Note: Browser doesn't store a value for ActiveLinkColor
  79.   defaultActiveColor = defaultLinkColor;
  80.   defaultVisitedColor =  browserColors.VisitedLinkColor;
  81.   defaultBackgroundColor=  browserColors.BackgroundColor;
  82.  
  83.   // Get the colors and image set by prefs init code 
  84.   customTextColor = gDialog.NormalData.getAttribute("value"); 
  85.   customLinkColor = gDialog.LinkData.getAttribute("value");
  86.   customActiveColor = gDialog.ActiveLinkData.getAttribute("value");
  87.   customVisitedColor = gDialog.VisitedLinkData.getAttribute("value");
  88.   customBackgroundColor = gDialog.BackgroundColorData.getAttribute("value");
  89.   backgroundImage = gDialog.BackgroundImageData.getAttribute("value");
  90.   if (backgroundImage)
  91.     gDialog.BackgroundImageInput.value = backgroundImage;
  92.  
  93.   // "value" attribute value is a string conversion of boolean!
  94.   if( document.getElementById( "useCustomColors" ).value == "true" )
  95.     UseCustomColors();
  96.   else
  97.     UseDefaultColors();
  98.  
  99.   return true;
  100. }                   
  101.  
  102. function GetColorAndUpdate(ColorWellID)
  103. {
  104.   // Only allow selecting when in custom mode
  105.   if (!gDialog.CustomColorsRadio.selected) return;
  106.  
  107.   var colorObj = new Object;
  108.   var colorWell = document.getElementById(ColorWellID);
  109.   if (!colorWell) return;
  110.  
  111.   // Don't allow a blank color, i.e., using the "default"
  112.   colorObj.NoDefault = true;
  113.  
  114.   switch( ColorWellID )
  115.   {
  116.     case "textCW":
  117.       colorObj.Type = "Text";
  118.       colorObj.TextColor = customTextColor;
  119.       break;
  120.     case "linkCW":
  121.       colorObj.Type = "Link";
  122.       colorObj.TextColor = customLinkColor;
  123.       break;
  124.     case "activeCW":
  125.       colorObj.Type = "ActiveLink";
  126.       colorObj.TextColor = customActiveColor;
  127.       break;
  128.     case "visitedCW":
  129.       colorObj.Type = "VisitedLink";
  130.       colorObj.TextColor = customVisitedColor;
  131.       break;
  132.     case "backgroundCW":
  133.       colorObj.Type = "Page";
  134.       colorObj.PageColor = customBackgroundColor;
  135.       break;
  136.   }
  137.  
  138.   window.openDialog("chrome://editor/content/EdColorPicker.xul", "_blank", "chrome,close,titlebar,modal", "", colorObj);
  139.  
  140.   // User canceled the dialog
  141.   if (colorObj.Cancel)
  142.     return;
  143.  
  144.   var color = "";
  145.   switch( ColorWellID )
  146.   {
  147.     case "textCW":
  148.       color = customTextColor = colorObj.TextColor;
  149.       gDialog.NormalData.setAttribute("value", color); 
  150.       break;
  151.     case "linkCW":
  152.       color = customLinkColor = colorObj.TextColor;
  153.       gDialog.LinkData.setAttribute("value", color);
  154.       break;
  155.     case "activeCW":
  156.       color = customActiveColor = colorObj.TextColor;
  157.       gDialog.ActiveLinkData.setAttribute("value", color);
  158.       break;
  159.     case "visitedCW":
  160.       color = customVisitedColor = colorObj.TextColor;
  161.       gDialog.VisitedLinkData.setAttribute("value", color);
  162.       break;
  163.     case "backgroundCW":
  164.       color = customBackgroundColor = colorObj.BackgroundColor;
  165.       gDialog.BackgroundColorData.setAttribute("value", color);
  166.       break;
  167.   }
  168.   setColorWell(ColorWellID, color); 
  169.   SetColorPreview(ColorWellID, color);
  170. }
  171.  
  172. function SetColorPreview(ColorWellID, color)
  173. {
  174.   switch( ColorWellID )
  175.   {
  176.     case "textCW":
  177.       gDialog.NormalText.setAttribute(styleStr,colorStyle+color);
  178.       break;
  179.     case "linkCW":
  180.       gDialog.LinkText.setAttribute(styleStr,colorStyle+color);
  181.       break;
  182.     case "activeCW":
  183.       gDialog.ActiveLinkText.setAttribute(styleStr,colorStyle+color);
  184.       break;
  185.     case "visitedCW":
  186.       gDialog.VisitedLinkText.setAttribute(styleStr,colorStyle+color);
  187.       break;
  188.     case "backgroundCW":
  189.       // Must combine background color and image style values
  190.       var styleValue = backColorStyle+color;
  191.       if (backgroundImage)
  192.         styleValue += ";"+backImageStyle+backgroundImage+");";
  193.  
  194.       gDialog.ColorPreview.setAttribute(styleStr,styleValue);
  195.       previewBGColor = color;
  196.       break;
  197.   }
  198. }
  199.  
  200. function UseCustomColors()
  201. {
  202.   SetElementEnabledById("TextButton", true);
  203.   SetElementEnabledById("LinkButton", true);
  204.   SetElementEnabledById("ActiveLinkButton", true);
  205.   SetElementEnabledById("VisitedLinkButton", true);
  206.   SetElementEnabledById("BackgroundButton", true);
  207.   SetElementEnabledById("Text", true);
  208.   SetElementEnabledById("Link", true);
  209.   SetElementEnabledById("Active", true);
  210.   SetElementEnabledById("Visited", true);
  211.   SetElementEnabledById("Background", true);
  212.  
  213.   SetColorPreview("textCW",       customTextColor);
  214.   SetColorPreview("linkCW",       customLinkColor);
  215.   SetColorPreview("activeCW",     customActiveColor);
  216.   SetColorPreview("visitedCW",    customVisitedColor);
  217.   SetColorPreview("backgroundCW", customBackgroundColor);
  218.  
  219.   setColorWell("textCW",          customTextColor);
  220.   setColorWell("linkCW",          customLinkColor);
  221.   setColorWell("activeCW",        customActiveColor);
  222.   setColorWell("visitedCW",       customVisitedColor);
  223.   setColorWell("backgroundCW",    customBackgroundColor);
  224.  
  225.   gDialog.NormalData.setAttribute("value",          customTextColor); 
  226.   gDialog.LinkData.setAttribute("value",            customLinkColor);
  227.   gDialog.ActiveLinkData.setAttribute("value",      customActiveColor);
  228.   gDialog.VisitedLinkData.setAttribute("value",     customVisitedColor);
  229.   gDialog.BackgroundColorData.setAttribute("value", customBackgroundColor);
  230. }
  231.  
  232. function UseDefaultColors()
  233. {
  234.   SetColorPreview("textCW",       defaultTextColor);
  235.   SetColorPreview("linkCW",       defaultLinkColor);
  236.   SetColorPreview("activeCW",     defaultActiveColor);
  237.   SetColorPreview("visitedCW",    defaultVisitedColor);
  238.   SetColorPreview("backgroundCW", defaultBackgroundColor);
  239.  
  240.   // Setting to blank color will remove color from buttons,
  241.   setColorWell("textCW",       "");
  242.   setColorWell("linkCW",       "");
  243.   setColorWell("activeCW",     "");
  244.   setColorWell("visitedCW",    "");
  245.   setColorWell("backgroundCW", "");
  246.  
  247.   // Disable color buttons and labels
  248.   SetElementEnabledById("TextButton", false);
  249.   SetElementEnabledById("LinkButton", false);
  250.   SetElementEnabledById("ActiveLinkButton", false);
  251.   SetElementEnabledById("VisitedLinkButton", false);
  252.   SetElementEnabledById("BackgroundButton", false);
  253.   SetElementEnabledById("Text", false);
  254.   SetElementEnabledById("Link", false);
  255.   SetElementEnabledById("Active", false);
  256.   SetElementEnabledById("Visited", false);
  257.   SetElementEnabledById("Background", false);
  258.   
  259.   // Note that we leave custom colors set even if 
  260.   //  custom colors pref is false (we just ignore the colors)
  261. }
  262.   
  263. function ChooseImageFile()
  264. {
  265.   // Get a local image file, converted into URL format
  266.   var fileName = GetLocalFileURL("img");
  267.   if (fileName)
  268.   {
  269.     gDialog.BackgroundImageInput.value = fileName;
  270.     ValidateAndPreviewImage(true);
  271.   }
  272.   SetTextboxFocus(gDialog.BackgroundImageInput);
  273. }
  274.  
  275. function ChangeBackgroundImage()
  276. {
  277.   // Don't show error message for image while user is typing
  278.   ValidateAndPreviewImage(false);
  279. }
  280.  
  281. function ValidateAndPreviewImage(ShowErrorMessage)
  282. {
  283.   // First make a string with just background color
  284.   var styleValue = backColorStyle+previewBGColor+";";
  285.  
  286.   var image = TrimString(gDialog.BackgroundImageInput.value);
  287.   if (image)
  288.   {
  289.     backgroundImage = image;
  290.     // Append image style
  291.     styleValue += backImageStyle+backgroundImage+");";
  292.   }
  293.   else
  294.     backgroundImage = "";
  295.  
  296.   // Set style on preview (removes image if not valid)
  297.   gDialog.ColorPreview.setAttribute(styleStr, styleValue);
  298.   
  299.   // Set the pref data so pref code saves it 
  300.   gDialog.BackgroundImageData.setAttribute("value", backgroundImage ? backgroundImage : "");
  301. }
  302.  
  303.